﻿<?php
class newsComponent extends sfComponent{
	public function execute($request){
		$data = array('perpage' => 3);
		$data['pagination']	= array(
			'page'		=> intval($this->page),
			'limit'		=> sfConfig::get('app_news_index_limit', 6),
			'total'		=> 0,
			'router'	=> 'news',
			'params'	=> array('cate_id' => intval($this->cate_id), 'id' => intval($this->id))
		);
		$data['filter'] = array(
			'filter_cate_id'		=> intval($this->cate_id),
			'filter_ids_notin' 	=> intval($this->id)
		);
		$data['act'] = strval($this->act);
		switch ($data['act']){
			case 'new': 
				$data['pagination']['limit']	= sfConfig::get('app_home_news_limit', 6);
				$data['news'] = News::getDataListFrontEnd(array(),$data['pagination']);
				break;
			case 'index': 
				$data['perpage'] = 2;
				$data['news'] = News::getDataListFrontEnd($data['filter'],$data['pagination']);
				$data['pagination']['total']		= News::getDataListCountFrontEnd($data['filter']);
				break;
			case 'detail':
				$data['detail'] = News::getDataByIdFrontEnd(intval($this->id));
				$data['pagination']['limit']	= sfConfig::get('app_news_detail_limit', 6);
				$data['news'] = News::getDataListFrontEnd($data['filter'],$data['pagination']);
				$data['pagination']['total']		= News::getDataListCountFrontEnd($data['filter']);
				
				$this->setVar('data', $data);
				break;
		}
		$this->setVar('data', $data);
	}
}